<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<!doctype html>
<html>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;系统管理&gt;基础信息管理&gt;意见箱维护</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
			<button type="button" class="btn dpbtn_grey_default" onclick="update();">修改</button>
			<button type="button" class="btn dpbtn_red" onclick="del();">删除</button>
		</div>
		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>

	<form class="form-horizontal m-t" id="commentForm">
		<div class="ibox-content" id="hiddenstyle" style="display: none;">
			<div class="form-group">
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<select id="boxName" name="boxName" class="form-control"></select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代码：</label>
				<div class="col-sm-8">
					<select id="boxCode" name="boxCode" class="form-control"><option
							value="1">1</option>
						<option value="2">2</option></select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">说明：</label>
				<div class="col-sm-8">
					<textarea id="suggestion" name="suggestion" minlength="6"
						maxlength="20" class="form-control" required=""
						aria-required="true" placeholder="请输入说明">123</textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remarks" name="remarks" minlength="6" maxlength="20"
						type="text" class="form-control" required="" aria-required="true"
						placeholder="请输入备注">
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-3">
					<button class="btn dpbtn_blue" type="button" onclick="save();">提交</button>
				</div>
			</div>
		</div>
	</form>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>

	<!-- custom js -->
	<%@include
		file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>

	<!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
	<script type="text/javascript">
    
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		var lastSel;
	    jQuery(function($) {  
	    	getData();
	    });
	    
	    //获取意见箱状态
	    $(function(){
			$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"OpinionStatus"
	 			},
	 			success: function(datas){
	 				  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var content = '';
		 				      for(var i=0;i<result.length;i++){
		 				          content +='<option value="">'+result[i].name+'</option>';
		 				      }
		 				      $("#boxName").html(content);
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	              }
		    });
		
		});
	    
	    
	    var getData = function()
	    {
	       winWidth = $(window).width();
       	   var winHeight = document.body.offsetHeight - 300;
    	   var win = winWidth / 7 - 20;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
		  jQuery("#table_list_1").jqGrid
		  ({
	        url:'${basePath}/SuggestionBoxController/getSuggestionBoxtPages',
	        datatype : "json",
	        colNames : [ '编号', '名称', '代码', '备注'],
	        colModel : [ 
	                     {name: 'id',index: 'id',width: win, hidden:true},
	                  	 {name: 'boxName',index: 'boxName',width: win,align: "center",sorttype: "float"},
	               		 {name: 'boxCode',index: 'boxCode',width: win,align: "center",sorttype: "float"},
	            		 {name: 'remarks',index: 'remarks',width: win,align: "center",sorttype: "float"},
	                   ],
              mtype : "post",
              height: winHeight,
              width:winWidth,  
              autowidth: true,
              shrinkToFit: true,
              rowNum: 15,
	           rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              hidegrid: false,
              multiselect : true,		//实现单选    multiboxonly:true   beforeSelectRow: true,
              multiboxonly:false,  
              beforeSelectRow: false,
              altRows:true,
              altclass:'someClass',
              onSelectRow:function(id){
            	  lastSel=id;
              },
              loadComplete:function(datas){
            	  if (datas.flag == "100100") {
                      layer.msg("查询成功!", {icon: 6, time: 1000});
                      return;
                  }
            	  if(datas.flag == '100802') {
    				  top.location.href = thisLoginUrl;
    				  return;
    			  }

            	  layer.msg(datas.message, {icon: 2});
              }
	      });
	    }
	    
	    window.onresize = function()
	    {
	    	 $("#table_list_1").setGridWidth($(window).width()-80);
	    	 $("#table_list_1").setGridHeight($(window).height() / 2.5);
	    }
	    
	    //搜索
	    var query = function()
	    {
	    	var remitAccount = document.getElementById("remitAccount").value.trim();
	    	$("#table_list_1").jqGrid("setGridParam",{
	    		url:'${basePath}/SuggestionBoxController/getSuggestionBoxPages',
   				postData:{
   		        	"remitAccount":remitAccount
   		        },
   				datatype:"json"
	    	}).trigger("reloadGrid")
	    }
	    
	    var add = function()
	    {
	    	var index = layer.open({
	    	  	title:'意见箱添加',
	    	  	type: 1,
		    	area: ['480px', '50%'], //宽高
	   			content: $('#hiddenstyle'),
	    	  	end: function () 
	    	  	{
	    		  refresh();
	          	}
	    	});
	    }
	    
	    var save = function()
	    {
// 	    	var validstatus = $("#commentForm").valid();
	    	
// 	    	if(validstatus)
// 	    	{
	    		var data = $('#commentForm').serialize();
	    		$.dpAjax({
		    		url:'${basePath}/SuggestionBoxController/insert',
		    		data:data,
	    			success: function(datas){
		    			  if(datas.flag == "100100")
						  {
							  layer.msg('执行成功！', {icon: 6});
							  //layer.close(1);
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	                 }
		    	});
// 	    	}
	    }
	    
	    var del = function()
	    {
	    	var rowData = jQuery('#table_list_1').jqGrid('getGridParam','selarrrow');  
	    	if(rowData.length < 1)
	    	{  
	    		layer.msg("请选择要删除的数据信息！", {icon: 5});
				return;
	    	}
	    	
	    	
	    	for(var i=0;i<rowData.length;i++)
	    	{
	    		var mainId = jQuery('#table_list_1').jqGrid('getCell',rowData[i],'id'); 
    			layer.confirm('您确认要删除吗？', {
    			  btn: ['确定','取消'] //按钮
    			},function(){
    				layer.closeAll();
    				$.dpAjax({
    		    		url:'${basePath}/SuggestionBoxController/delete',
    	    			data:{"id":mainId},
    	    			success: function(datas){
    	    			  if(datas.flag == "100100")
  						  {
  							  layer.msg('执行成功！', {icon: 6});
  							  return;
  						  }
  						  if(datas.flag == "100200")
  		                  {
  							  $.fn.showDatas({"datas":datas});
  		                	  return;
  		                  }
  						  layer.msg(datas.message, {icon: 2});
    	                }
    		    	});
    			});
	    	}
	    }
	    
	    var update = function()
	    {
	    	$.dpAjax({
	    		url:'${basePath}/SuggestionBoxController/getById',
				data:{"id":lastSel},
				success: function(datas){
					var content = '<div class="ibox-content">'
	    				+ '<form class="form-horizontal m-t" id="commentForm">'
	    				+'<input id="id" name="id" type="hidden" />'
	    					+ '<div class="form-group">'
			    				+ '<label class="col-sm-3 control-label">名称：</label>'
			    				+ '<div class="col-sm-8">'
			    				+ '<select id="boxName" name="boxName" class="form-control"><option value="未回复">未回复</option><option value="已回复">已回复</option></select>'
			    				+ '</div>'
    						+ '</div>'
		    				+ '<div class="form-group">'
			    				+ '<label class="col-sm-3 control-label">代码：</label>'
			    				+ '<div class="col-sm-8">'
			    					+ '<select id="boxCode" name="boxCode" class="form-control"><option value="1">1</option><option value="2">2</option></select>'
			    				+ '</div>'
		    				+ '</div>'
		    				+ '<div class="form-group">'
			    				+ '<label class="col-sm-3 control-label">说明：</label>'
			    				+ '<div class="col-sm-8">'
			    					+ '<textarea  id="suggestion" name="suggestion" minlength="6" maxlength="20"  class="form-control" required="" aria-required="true" placeholder="请输入说明" >123</textarea>'
			    				+ '</div>'
	    					+ '</div>'
	    					+ '<div class="form-group">'
			    				+ '<label class="col-sm-3 control-label">备注：</label>'
			    				+ '<div class="col-sm-8">'
			    					+ '<input id="remarks" name="remarks" minlength="6" maxlength="20" type="text" class="form-control" required="" aria-required="true" placeholder="请输入备注" >'
			    				+ '</div>'
    						+ '</div>'
	    					+ '<div class="form-group">'
		    					+ '<div class="col-sm-4 col-sm-offset-3">'
		    						+ '<button class="btn dpbtn_blue" type="button" onclick="doUpdate();">提交</button>'
		    					+ '</div>'
	    					+ '</div>'
	    				+ '</form>'
    				+ '</div>';

					//页面层
					var index = layer.open({
			    	  title:'打款名单修改',
			    	  type: 1,
			    	  skin: 'layui-layer-rim', //加上边框
			    	  area: ['600px', '400px'], //宽高
			    	  content: content
			    	});
					document.getElementById("id").value=datas.result.id;
					document.getElementById("boxName").value=datas.result.boxName;
					document.getElementById("boxName").innerHtml="已回复";
					document.getElementById("boxCode").value=datas.result.boxCode;
					document.getElementById("boxCode").innerHtml="1";
					document.getElementById("remarks").value=datas.result.remarks;
					document.getElementById("suggestion").value=datas.result.suggestion;
				jQuery("#table_list_1").trigger("reloadGrid");
            }
	    	});
	    }
	    var doUpdate=function(){
    		var data = $('#commentForm').serialize();
    		$.dpAjax({
	    		url:'${basePath}/SuggestionBoxController/update',
	    		data:data,
    			success: function(datas){
	    			  if(datas.flag == "100100")
					  {
						  layer.msg('执行成功！', {icon: 6});
						  
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
					  layer.msg(datas.message, {icon: 2});
                 }
	    	});
	    }
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
	    }
    </script>
</body>
</html>
